package com.yc.sole.erp.controller;

import com.yc.sole.erp.biz.StockLogBiz;
import com.yc.sole.erp.request.StockLogQueryReq;
import com.yc.sole.erp.response.StockLogResp;
import com.yc.sole.framework.mybatis.page.BaseBatchIdsReq;
import com.yc.sole.framework.mybatis.page.BasePageReq;
import com.yc.sole.framework.mybatis.page.Paging;
import com.yc.sole.framework.result.Result;
import com.yc.sole.framework.validate.DeleteGroup;
import com.yc.sole.framework.web.PreAuth;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yizuomin
 * @date 2024-01-26
 **/
@Slf4j
@RestController
@RequiredArgsConstructor
public class StockLogController {

    private final StockLogBiz stockLogBiz;

    /**
     * 通过id批量删除
     *
     * @param baseDeleteReq
     * @return RestResult
     */
    @PreAuth(value = "erp:stockLog:delete", description = "删除")
    @PostMapping("/api/erp/stockLog/deleteStockLog")
    public Result<Void> deleteStockLog(@RequestBody @Validated(DeleteGroup.class) BaseBatchIdsReq baseDeleteReq) {
        stockLogBiz.deleteStockLogByIds(baseDeleteReq.getIds());
        return Result.success();
    }

    /**
     * 根据id查询
     *
     * @param id
     * @return Result
     */
    @PreAuth(value = "erp:stockLog:select", description = "查询")
    @PostMapping("/api/erp/stockLog/selectStockLogById/{id}")
    public Result<StockLogResp> selectStockLogById(@PathVariable Long id) {
        return Result.data(stockLogBiz.selectStockLogById(id));
    }

    /**
     * 分页查询
     *
     * @param basePageReq
     * @return Result
     */
    @PreAuth(value = "erp:stockLog:select", description = "查询")
    @PostMapping("/api/erp/stockLog/selectStockLogPage")
    public Result<Paging<StockLogResp>> selectStockLogPage(@RequestBody @Validated BasePageReq<StockLogQueryReq> basePageReq) {
        return Result.data(stockLogBiz.selectStockLogPage(basePageReq.toPage(), basePageReq.getQuery()));
    }
}
